home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-26 | 53.4 KB | 2,289 lines |
- Newsgroups: comp.sources.misc
- From: aknight@ourgang.Prime.COM (Andy Knight x445)
- Subject: v24i022: mced - C-shell history command line editor v2.0, Part01/01
- Message-ID: <1991Oct26.220453.5036@sparky.imd.sterling.com>
- X-Md4-Signature: edcea2f63c01367b55b9cba54dcf9620
- Date: Sat, 26 Oct 1991 22:04:53 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: aknight@ourgang.Prime.COM (Andy Knight x445)
- Posting-number: Volume 24, Issue 22
- Archive-name: mced/part01
- Environment: UNIX, C-shell
- Supersedes: mced: Volume 21, Issue 94
-
- Here is mced2.0, which now has vi-mode. There are some minor
- bug fixes and enhancements as well, which should make it somewhat
- faster and more portable. (Vi-mode is also more elaborate than
- emacs-mode, including . p <nn>function and undo. :-))
-
- ------
- McEd is a utility which allows you to browse, edit and execute
- commands from your C-shell history list. It is not a shell itself,
- but it executes the commands in your current shell as if you had
- typed them in. The editing functions are based on gnuemacs or vi,
- see the Makefile to select either one.
-
- ------
- Andy Knight, SunOS_humor% man reboot | sed -n '/Avoid/,/fire/p'
- Computervision Corp. >>>> -n Avoid the sync(1). It can be used if
- aknight@ourgang.prime.com >>>> a disk or the processor is on fire.
- ------
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # README
- # Makefile
- # mced.1
- # Bugs
- # main.c
- # vi_edit.c
- # emacs_edit.c
- # getch.c
- # getch.h
- # config.h
- # This archive created: Fri Oct 18 14:38:05 1991
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'README'" '(2131 characters)'
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- sed 's/^X//' << \SHAR_EOF > 'README'
- XDESCRIPTION:
- X
- XMcEd is a utility which allows you to browse, edit and execute
- Xcommands from your C-shell history list. It is not a shell itself,
- Xbut it executes the commands in your current shell as if you had
- Xtyped them in. The editing functions are based on gnuemacs or vi,
- Xsee the Makefile to select either one.
- X
- X
- XUSAGE:
- X
- XAfter making the executable, Put the following
- Xsomewhat lengthly :-) alias for "=" in your .cshrc:
- X
- Xalias = "history -h 50 >\! /tmp/eh$$;mced \!*;
- Xsource -h /tmp/ec$$;source /tmp/ec$$;/bin/rm /tmp/ec$$"
- X(one line)
- X
- X``='' now copies the commands in your history list into memory
- Xand allows you to browse and edit, <CR> executes the command.
- XSee the man page for details on editing.
- X
- XIf possible, avoid using SYSV curses. If you have no choice,
- Xyou must put #define SYSVcurses somewhere near the top of config.h.
- X
- X
- XI hope that you will find mced useful, - let me know if you
- Xhave any problems, suggestions etc..
- X
- X-Andy [Mc]Knight
- X
- X
- X/*
- X * This software is Copyright (c) 1991 by Andy Knight
- X * (getch.c and getch.h Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe)
- X *
- X * Permission is hereby granted to copy, distribute or otherwise
- X * use any part of this package as long as you do not try to make
- X * money from it or pretend that you wrote it. This copyright
- X * notice must be maintained in any copy made.
- X *
- X * Use of this software constitutes acceptance for use in an AS IS
- X * condition. There are NO warranties with regard to this software.
- X * In no event shall the author be liable for any damages whatsoever
- X * arising out of or in connection with the use or performance of this
- X * software. Any use of this software is at the user's own risk.
- X *
- X * If you make modifications to this software that you feel
- X * increases it usefulness for the rest of the community, please
- X * email the changes, enhancements, bug fixes as well as any and
- X * all ideas to me. This software is going to be maintained and
- X * enhanced as deemed necessary by the community.
- X *
- X * " ... Freely you have recieved, freely give" <Matthew 10:8>
- X *
- X * Andy Knight
- X * aknight@ourgang.prime.com
- X */
- SHAR_EOF
- if test 2131 -ne "`wc -c < 'README'`"
- then
- echo shar: error transmitting "'README'" '(should have been 2131 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Makefile'" '(1011 characters)'
- if test -f 'Makefile'
- then
- echo shar: will not over-write existing file "'Makefile'"
- else
- sed 's/^X//' << \SHAR_EOF > 'Makefile'
- X#
- X# Makefile for mced
- X#
- X# To install this utility do the following:
- X# 1) Select vi or emacs mode by uncommenting one of the
- X# OBJECTS lines below.
- X# 2) Fill in the BINDIR and MANDIR variables.
- X# 3) Type "make install" on the command line.
- X# 4) Type "make clean" on the command line to clean up after install.
- X#
- X#
- X#
- X# definitions for EMACS EDIT mode:
- X#OBJECTS = main.o emacs_edit.o getch.o
- X#
- X# definitions for VI EDIT mode:
- XOBJECTS = main.o vi_edit.o getch.o
- X#
- X# Where to stick the executable on install
- XBINDIR=/usr/local/bin
- X#
- X# Where to stick the man page on install
- XMANDIR=/usr/local/man/man1
- X#
- XLDFLAGS = -lcurses -ltermcap
- X#
- XCFLAGS = -O ## do not use optimizer on SunOS 4.0.3S ##
- X
- Xmced : $(OBJECTS)
- X $(CC) $(TARGET_ARCH) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
- X
- Xman : mced.1
- X cat mced.1 | nroff -man > mced.man
- X
- Xinstall : mced
- X install -s -c mced $(BINDIR)
- X install -m 644 mced.1 $(MANDIR)/mced.1
- X ln -s $(MANDIR)/mced.1 $(MANDIR)/=.1
- X
- Xclean :
- X rm -f mced core $(OBJECTS)
- X
- SHAR_EOF
- if test 1011 -ne "`wc -c < 'Makefile'`"
- then
- echo shar: error transmitting "'Makefile'" '(should have been 1011 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'mced.1'" '(4179 characters)'
- if test -f 'mced.1'
- then
- echo shar: will not over-write existing file "'mced.1'"
- else
- sed 's/^X//' << \SHAR_EOF > 'mced.1'
- X.TH McEd 1 "1 October 1991"
- X.SH NAME
- Xmced \- McKnight's unix history Command line Editor
- X.SH SYNOPSIS
- X.B "= [string]"
- X.SH DESCRIPTION
- X.I "mced"
- Xis a utility giving the C-shell added history flexibility with
- Xbrowsing and editing functions for commands in the history list.
- X.I "mced"
- Xis driven by an alias which should be defined as follows:
- X.nf
- X.sp
- Xalias = "history -h 50 >\\! /tmp/eh$$;mced \\!*;source -h /tmp/ec$$;\
- Xsource /tmp/ec$$;/bin/rm /tmp/ec$$"
- X.SH
- X``='' now copies the commands in your history list into memory
- Xand positions you at the most recent command, or ``= <string>''
- Xpositions you at the first command that begins with <string>.
- XThe command is now edited emacs OR vi style, and executed by a <CR>,
- XCTRL-U and CTRL-W are used to cancel and delete just as usual.
- XShort commands are filtered out of the history list, the
- Xminimum length is set with MIN_CMD_LEN, defined in config.h.
- XConsecutive duplicate commands are filtered out as well.
- XIf you use tcsh, ksh, bash etc. you will probably not have much use for
- Xmced, as these shells have similar history editing built-in.
- X
- X.SH MOVING AROUND IN THE HISTORY LIST
- XThe up and down arrow keys index you through the history list,
- Xif <string> is used on the command line, CTRL-R and CTRL-S (emacs mode)
- Xor n (vi mode) search for the next occurrence.
- X
- X.SH
- X
- X.SH CURSOR MOVEMENT
- XThe standard emacs control and escape characters (or vi cursor motion
- Xcharacters) (CTRL-A, CTRL-B, CTRL-E, CTRL-F, ESC-B, ESC-F (^,$,w,b,h,l))
- Xand arrow keys are used to move around on the command line.
- XESC-M moves to the middle of the command line.
- X.SH EMACS EDITING SUMMARY
- X.I "mced"
- X.RS +.6i
- X.nf
- X.ta 2.5i
- X.sp
- XEditing functions
- X.sp
- Xbeginning of line CTRL-A
- Xbackward char CTRL-B
- Xdelete char CTRL-D
- Xend of line CTRL-E
- Xforward char CTRL-F
- Xkill to end of line CTRL-K
- Xredraw command CTRL-L
- Xdown history CTRL-N
- Xup history CTRL-P
- Xsearch backward CTRL-R
- Xsearch forward CTRL-S
- Xtranspose characters CTRL-T
- Xbackward delete char Delete
- Xbackward delete word ESC-Delete, CTRL-W
- Xbackward word ESC-B
- Xchange case character ESC-C **
- Xdelete word forward ESC-D
- Xforward word ESC-F
- Xdowncase command ESC-L **
- Xmiddle cursor ESC-M **
- Xupcase command ESC-U **
- Xexecute command <CR>
- Xquit CTRL-U, CTRL-C
- X
- X** Function behaves differently than in gnuemacs
- X
- X--------------------------------------------------------------
- X
- X.SH VI EDITING SUMMARY
- X.I "mced"
- X.RS +.6i
- X.nf
- X.ta 2.5i
- X.sp
- XEditing functions
- X.sp
- Xbeginning of line ^
- Xend of line $
- Xmiddle of line ESC-M **
- Xbackward char h
- Xforward char l
- Xbackward word b
- Xforward word w
- Xdown history j
- Xup history k
- Xsearch backward n
- Xredraw command CTRL-L
- Xinsert at current pos i
- Xinsert at beginning I
- Xappend a
- Xappend at end A
- Xdelete char x
- Xdelete word forward dw,dW
- Xkill to end of line D
- Xput last delete p,P
- Xredo last change .
- Xundo last change u
- Xbackward delete word CTRL-W **
- Xchange case character ~
- Xchange word cw,cW
- Xchange to end of line C
- Xreplace one character r
- Xreplace forward R
- Xdowncase command ESC-L **
- Xupcase command ESC-U **
- Xexecute command <CR> *
- Xquit CTRL-U, CTRL-C, dd
- X
- X<nn> "function" may be used to repeat the function <nn> times.
- X
- X* Will also execute command in insert mode
- X** Function is not in standard vi screen editor
- X
- X--------------------------------------------------------------
- X
- XLines may be joined together by doing a delete at the end
- Xof the command line in emacs mode, or "J" in vi mode.
- X
- XKey mappings for sun R function keys around the arrow keys
- Xare defined to do some cursor movement and other functions,
- Xsee source for details ({emacs,vi}_edit.c)
- X
- XThere is currently no undo function (in emacs mode).
- X
- XThe window for the command always occupies the last two lines
- Xon your screen, the command length cannot go beyond this.
- X(Note: if you use SysV curses the command will occupy the first
- Xtwo lines on the screen)
- X
- X.SH AUTHOR
- XAndy [Mc]Knight, Computervision;
- Xaknight@ourgang.prime.com
- X.sp
- Xgetch.c and getch.h were snatched
- Xfrom scan, written by Patrick J. Wolfe
- X.SH "THANKS TO"
- XMichael R. Haley, Tize Ma, Kevin Cosgrove and Brian Murray
- Xfor their help reviewing and beta testing mced2.0.
- X.SH SEE ALSO
- X.BR tcsh(1),
- X.BR gnuemacs(1),
- X.BR vi(1),
- X.BR csh_builtins(1)
- SHAR_EOF
- if test 4179 -ne "`wc -c < 'mced.1'`"
- then
- echo shar: error transmitting "'mced.1'" '(should have been 4179 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Bugs'" '(542 characters)'
- if test -f 'Bugs'
- then
- echo shar: will not over-write existing file "'Bugs'"
- else
- sed 's/^X//' << \SHAR_EOF > 'Bugs'
- X1 - foreach loops will not execute from mced.
- X (!! immediately after will execute the edited foreach)
- X
- X2 - Everything after # in a command string is ignored,
- X put a backslash before # so source will not treat
- X it as the start of a comment.
- X
- X3 - mced cannot be stopped (CTRL-Z) and then restarted,
- X the command sequence in the "=" alias is broken when
- X the process is stopped.
- X
- X4 - In a Sunview cmdtool the screen goes blank when mced
- X is invoked, after the command is executed the screen
- X is redrawn without the executed command showing.
- X
- SHAR_EOF
- if test 542 -ne "`wc -c < 'Bugs'`"
- then
- echo shar: error transmitting "'Bugs'" '(should have been 542 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'main.c'" '(8124 characters)'
- if test -f 'main.c'
- then
- echo shar: will not over-write existing file "'main.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'main.c'
- X/*
- X * This software is Copyright (c) 1991 by Andy Knight
- X *
- X * Permission is hereby granted to copy, distribute or otherwise
- X * use any part of this package as long as you do not try to make
- X * money from it or pretend that you wrote it. This copyright
- X * notice must be maintained in any copy made.
- X *
- X * Use of this software constitutes acceptance for use in an AS IS
- X * condition. There are NO warranties with regard to this software.
- X * In no event shall the author be liable for any damages whatsoever
- X * arising out of or in connection with the use or performance of this
- X * software. Any use of this software is at the user's own risk.
- X *
- X * If you make modifications to this software that you feel
- X * increases it usefulness for the rest of the community, please
- X * email the changes, enhancements, bug fixes as well as any and
- X * all ideas to me. This software is going to be maintained and
- X * enhanced as deemed necessary by the community.
- X *
- X * " ... Freely you have recieved, freely give" <Matthew 10:8>
- X *
- X * Andy Knight
- X * aknight@ourgang.prime.com
- X */
- X
- X#include "config.h"
- X
- X
- Xchar buff[BUFSIZE];
- X
- Xchar hfile[20], cfile[20];
- Xchar vern[] = "#";
- Xchar spc[] = " ";
- Xchar prompt[] = PROMPT;
- Xchar *hist[MAX_H_READ], cstr[MAX_CH], sstr[30];
- Xint edit_mode, x_pos, savex_pos, xend, cur_cmd, last_hline, xbeg;
- Xint fd, index_cmd();
- XFILE *fptr;
- XSIGTYPE die_curses(), die_normal();
- XWINDOW *win;
- Xvoid my_wmove(), eat_white(), add_hline(), cmd_to_win(), win_to_cmd();
- Xvoid my_waddstr(), my_winsch(), my_wdelch(), case_lower(), case_upper();
- Xvoid edit_line(), exit();
- X
- X#ifdef SYSVcurses
- Xstruct termio tio, tin;
- X#else
- Xstruct tchars tco, tcn;
- X#endif
- X
- X
- Xmain(argc, argv)
- X int argc;
- X char *argv[];
- X{
- X register i, j, bytes_read;
- X int last_length, pid;
- X
- X signal(SIGINT, die_normal); /* die cleanly */
- X/*
- X * get the shell process id (pid) to match $$ in the = alias
- X */
- X
- X pid = getppid();
- X sprintf(hfile, "/tmp/eh%d", pid);
- X sprintf(cfile, "/tmp/ec%d", pid);
- X xbeg = strlen(prompt);
- X/*
- X * open the history file
- X */
- X fd = open(hfile, 0);
- X if (fd == (int) -1)
- X {
- X perror(hfile); /* Note: DO NOT ATTEMPT TO STUFF THIS ALIAS, see README */
- X fprintf(stderr, "To execute mced use \"=\" with the following alias:\n");
- X fprintf(stderr, "alias = \"history -h 50 >\\! /tmp/eh$$;mced \\!*;");
- X fprintf(stderr, "source -h /tmp/ec$$;source /tmp/ec$$;/bin/rm /tmp/ec$$\"\n");
- X die_normal();
- X }
- X else
- X {
- X bytes_read = read(fd, buff, BUFSIZE);
- X if (bytes_read == -1)
- X {
- X perror(hfile);
- X die_normal();
- X }
- X if (bytes_read == BUFSIZE)
- X printf("Warning: BUFSIZE is too small, see config.h\n");
- X }
- X last_length = last_hline = j = 0;
- X for (i = 0; i < bytes_read; i++)
- X {
- X if (buff[i] == '\n')
- X {
- X if (i - j >= MIN_CMD_LEN && buff[j] != '=')
- X {
- X hist[last_hline] = &buff[j];
- X buff[i] = '\0';
- X /*** Remove redundant consecutive history lines ***/
- X if ((i - j) == last_length
- X && strcmp(&buff[j], hist[last_hline - 1]) == 0)
- X --last_hline;
- X last_length = i - j;
- X ++last_hline;
- X }
- X j = i + 1;
- X }
- X }
- X
- X --last_hline;
- X cur_cmd = last_hline;
- X
- X/*
- X * check for existence of history before going on
- X */
- X if (last_hline < 0)
- X {
- X fprintf(stderr, "No valid history\n");
- X die_normal();
- X }
- X
- X/*
- X * copy search string from command line
- X */
- X if (argc > 1)
- X {
- X strcpy(sstr, argv[1]);
- X if (argc > 2)
- X {
- X for (i = 3; i <= argc; i++)
- X {
- X strcat(sstr, spc);
- X strcat(sstr, argv[i - 1]);
- X }
- X }
- X cur_cmd = index_cmd(cur_cmd, -1);
- X }
- X strcpy(cstr, hist[cur_cmd]);
- X/*
- X * edit command and execute
- X */
- X edit_cmd();
- X
- X/*
- X * close and delete history temp file
- X */
- X close(fd);
- X unlink(hfile);
- X
- X/*
- X * open file and write command to it
- X */
- X if ((fptr = fopen(cfile, "w")) == NULL)
- X {
- X perror(cfile);
- X exit(0);
- X }
- X fprintf(fptr, "%s\n%s\n", vern, cstr);
- X fclose(fptr);
- X printf("\n");
- X}
- X
- X
- Xint
- Xindex_cmd(tcur_cmd, direc)
- X int tcur_cmd, direc;
- X{
- X register i, slen;
- X slen = strlen(sstr);
- X for (i = 0; i <= last_hline; i++)
- X {
- X if (tcur_cmd < 0)
- X tcur_cmd = last_hline;
- X if (tcur_cmd > last_hline)
- X tcur_cmd = 0;
- X if (strncmp(hist[tcur_cmd], sstr, slen) == 0)
- X return (tcur_cmd);
- X tcur_cmd += direc;
- X }
- X return (cur_cmd);
- X}
- X
- X
- XSIGTYPE
- Xdie_normal()
- X{
- X signal(SIGINT, SIG_IGN);
- X signal(SIGINT, die_normal);
- X/*
- X * close and delete history temp file
- X */
- X close(fd);
- X unlink(hfile);
- X
- X if ((fptr = fopen(cfile, "w")) == NULL)
- X {
- X perror(cfile);
- X exit(0);
- X }
- X fprintf(fptr, "%s\n", vern);
- X fclose(fptr);
- X exit(0);
- X}
- X
- X
- Xvoid
- Xadd_hline() /* add next hist line on delete at EOL */
- X{
- X if (cur_cmd < last_hline)
- X {
- X ++cur_cmd;
- X savex_pos = x_pos;
- X my_waddstr(hist[cur_cmd]);
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X }
- X else
- X beep();
- X}
- X
- X
- Xvoid
- Xmy_wmove(i)
- X int i;
- X{
- X int which_line;
- X which_line = ((i < COLS) ? 0 : 1);
- X wmove(win, which_line, (i - which_line * COLS));
- X}
- X
- X
- Xvoid
- Xmy_winsch(in_char)
- X int in_char;
- X{
- X int wrap_char;
- X if ((xend + 1) >= (COLS * 2))
- X {
- X beep();
- X }
- X else if (xend > (COLS - 1) && x_pos < COLS) /* wraparound */
- X {
- X ++xend;
- X wmove(win, 0, COLS - 1);
- X wrap_char = winch(win);
- X wmove(win, 1, 0);
- X winsch(win, wrap_char);
- X my_wmove(x_pos);
- X winsch(win, in_char);
- X my_wmove(++x_pos);
- X }
- X else
- X {
- X ++xend;
- X winsch(win, in_char);
- X my_wmove(++x_pos);
- X }
- X}
- X
- X
- Xvoid
- Xmy_wdelch()
- X{
- X int wrap_char;
- X --xend;
- X if (xend >= COLS && x_pos < COLS) /* wraparound */
- X {
- X wmove(win, 1, 0);
- X wrap_char = winch(win);
- X wdelch(win);
- X my_wmove(x_pos);
- X wdelch(win);
- X wmove(win, 0, COLS - 1);
- X winsch(win, wrap_char);
- X my_wmove(x_pos);
- X }
- X else
- X {
- X wdelch(win);
- X }
- X}
- X
- X
- Xvoid
- Xmy_waddstr(strng)
- X char strng[];
- X{
- X register i, len;
- X len = strlen(strng);
- X for (i = 0; i < len; i++)
- X {
- X my_winsch((int) strng[i]);
- X }
- X}
- X
- X
- Xvoid
- Xcmd_to_win() /* write prompt and command to window */
- X{
- X my_wmove(0);
- X wclear(win);
- X waddstr(win, prompt);
- X xend = x_pos = xbeg;
- X my_waddstr(cstr);
- X}
- X
- X
- Xvoid
- Xwin_to_cmd() /* get the edited line from the window */
- X{
- X int i;
- X my_wmove(xbeg);
- X for (i = 0; i <= (xend - xbeg); i++)
- X {
- X my_wmove(xbeg + i);
- X cstr[i] = winch(win);
- X }
- X cstr[xend - xbeg] = '\0';
- X}
- X
- X
- Xvoid
- Xcase_upper()
- X{
- X int i;
- X for (i = 0; i <= (xend - xbeg); i++)
- X {
- X if (islower(cstr[i]))
- X cstr[i] = toupper(cstr[i]);
- X }
- X}
- X
- X
- Xvoid
- Xcase_lower()
- X{
- X int i;
- X for (i = 0; i <= (xend - xbeg); i++)
- X {
- X if (isupper(cstr[i]))
- X cstr[i] = tolower(cstr[i]);
- X }
- X}
- X
- X
- XSIGTYPE
- Xdie_curses() /* interrupt signal */
- X{
- X signal(SIGINT, SIG_IGN);
- X signal(SIGINT, die_curses);
- X#ifdef SYSVcurses
- X if (ioctl(0, TCSETA, &tio) != 0)
- X perror("ioctl");
- X#else
- X if (ioctl(0, TIOCSETC, &tco) != 0)
- X perror("ioctl");
- X#endif
- X NOCBREAKF();
- X echo();
- X endwin();
- X/*
- X * close and delete history temp file
- X */
- X close(fd);
- X unlink(hfile);
- X
- X if ((fptr = fopen(cfile, "w")) == NULL)
- X {
- X perror(cfile);
- X exit(0);
- X }
- X fprintf(fptr, "%s\n", vern);
- X fclose(fptr);
- X printf("\n");
- X exit(0);
- X}
- X
- X
- Xvoid
- Xeat_white(direc, destruc) /* eat up initial whitespace */
- X int direc, destruc;
- X{
- X int lim;
- X if (direc == -1)
- X lim = xbeg;
- X else
- X lim = xend;
- X if (destruc == NO)
- X {
- X for (; isspace(winch(win));)
- X {
- X if (x_pos != lim)
- X {
- X x_pos += direc;
- X my_wmove(x_pos);
- X }
- X else
- X return;
- X }
- X return;
- X }
- X else /* actually delete */
- X {
- X for (; isspace(winch(win));)
- X {
- X if (x_pos != lim)
- X {
- X my_wdelch();
- X x_pos += direc;
- X my_wmove(x_pos);
- X if (!(isspace(winch(win))) && direc == 1)
- X my_wmove(--x_pos);
- X }
- X else
- X return;
- X }
- X return;
- X }
- X}
- SHAR_EOF
- if test 8124 -ne "`wc -c < 'main.c'`"
- then
- echo shar: error transmitting "'main.c'" '(should have been 8124 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'vi_edit.c'" '(15455 characters)'
- if test -f 'vi_edit.c'
- then
- echo shar: will not over-write existing file "'vi_edit.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'vi_edit.c'
- X/*
- X * This software is Copyright (c) 1991 by Andy Knight
- X *
- X * Permission is hereby granted to copy, distribute or otherwise
- X * use any part of this package as long as you do not try to make
- X * money from it or pretend that you wrote it. This copyright
- X * notice must be maintained in any copy made.
- X *
- X * Use of this software constitutes acceptance for use in an AS IS
- X * condition. There are NO warranties with regard to this software.
- X * In no event shall the author be liable for any damages whatsoever
- X * arising out of or in connection with the use or performance of this
- X * software. Any use of this software is at the user's own risk.
- X *
- X * If you make modifications to this software that you feel
- X * increases it usefulness for the rest of the community, please
- X * email the changes, enhancements, bug fixes as well as any and
- X * all ideas to me. This software is going to be maintained and
- X * enhanced as deemed necessary by the community.
- X *
- X * " ... Freely you have recieved, freely give" <Matthew 10:8>
- X *
- X * Andy Knight
- X * aknight@ourgang.prime.com
- X */
- X
- X#include "config.h"
- X
- X
- Xextern char *hist[], cstr[];
- Xextern int xbeg, cur_cmd, last_hline, pwolfe_getch();
- Xextern int edit_mode, x_pos, savex_pos, xend;
- X
- Xextern void my_wmove(), add_hline(), cmd_to_win(), win_to_cmd();
- Xextern void my_winsch(), my_waddstr(), case_upper();
- Xextern void my_wdelch(), case_lower(), eat_white();
- Xextern SIGTYPE die_curses(), die_normal();
- Xextern WINDOW *win;
- X
- X#ifdef SYSVcurses
- Xextern struct termio tio, tin;
- X#else
- Xextern struct tchars tco, tcn;
- X#endif
- X
- X
- Xedit_cmd()
- X{
- X int stop_it, p_init, xins_strt, edch, i, j, tmp_cmd;
- X int dot_mode, dot_iterations, n_iterations, n_times, indx;
- X char tch, dot_cmd;
- X char save_ins[MAX_W_SAVED + 1], save_del[MAX_W_SAVED + 1];
- X fprintf(stdout, "\n");
- X if (initscr() == ERR)
- X {
- X fprintf(stderr, "Curses won't initialize - help!\n");
- X die_normal();
- X }
- X signal(SIGINT, die_curses); /* die cleanly */
- X CBREAKF();
- X noecho();
- X#ifdef SYSVcurses
- X win = newwin(2, COLS, 0, 0);
- X#else
- X clearok(curscr, FALSE); /* SYSV curses clears it anyway ;-( */
- X win = newwin(2, COLS, LINES - 2, 0);
- X#endif
- X
- X cmd_to_win();
- X my_wmove(--x_pos);
- X wrefresh(win);
- X savex_pos = x_pos;
- X
- X#ifdef SYSVcurses /* disable STOP/START (CTRL-S) */
- X if (ioctl(0, TCGETA, &tio) != 0)
- X perror("ioctl");
- X tin = tio;
- X tin.c_iflag &= ~IXON;
- X if (ioctl(0, TCSETA, &tin) != 0)
- X perror("ioctl");
- X#else
- X if (ioctl(0, TIOCGETC, &tco) != 0)
- X perror("ioctl");
- X tcn = tco;
- X tcn.t_stopc = -1;
- X if (ioctl(0, TIOCSETC, &tcn) != 0)
- X perror("ioctl");
- X#endif
- X edit_mode = VI_NINS_MODE;
- X dot_iterations = 1;
- X dot_cmd = NO;
- X n_times = indx = 0;
- X p_init = NO;
- X for (; (edch = pwolfe_getch(win)) != '\n';)
- X {
- X if ((edch == 'u' || edch == 'U') && edit_mode == VI_NINS_MODE)
- X {
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X wrefresh(win);
- X continue;
- X }
- X if (edit_mode == VI_NINS_MODE && (edch == 'a' || edch == 'A'
- X || edch == 'i' || edch == 'I' || edch == 'p' || edch == 'P'
- X || edch == '.' || edch == 'x' || edch == 'd' || edch == 'D'
- X || edch == 'c' || edch == 'C' || edch == 'r' || edch == 'R'
- X || edch == '\~' || edch == 'X' || edch == ControlW
- X || edch == Sun_R1))
- X {
- X savex_pos = x_pos;
- X win_to_cmd(); /* for undo function */
- X my_wmove(x_pos);
- X }
- X if (edit_mode == VI_NINS_MODE)
- X {
- X if (edch == 'c')
- X {
- X indx = 0;
- X xins_strt = x_pos;
- X edit_mode = VI_c_MODE;
- X continue;
- X }
- X else if (edch == 'd')
- X {
- X edit_mode = VI_d_MODE;
- X continue;
- X }
- X else if (edch == 'r')
- X {
- X edit_mode = VI_r_MODE;
- X continue;
- X }
- X else if (edch == 'R')
- X {
- X indx = 0;
- X xins_strt = x_pos;
- X dot_mode = VI_NINS_MODE;
- X dot_cmd = 'R';
- X edit_mode = VI_R_MODE;
- X continue;
- X }
- X }
- X
- X if (isdigit(edch) && edit_mode == VI_NINS_MODE)
- X {
- X if (n_times != 0)
- X n_times *= 10;
- X n_times += edch - '0';
- X continue;
- X }
- X
- X if (n_times != 0)
- X {
- X n_iterations = n_times;
- X n_times = 0;
- X }
- X else
- X n_iterations = 1;
- X
- X if (edch == '\.' && edit_mode == VI_NINS_MODE)
- X {
- X if (dot_cmd != NO)
- X {
- X edch = dot_cmd;
- X edit_mode = dot_mode;
- X n_iterations = dot_iterations;
- X if (edch == 'i' || edch == 'a')
- X {
- X if (edch == 'a')
- X my_wmove(++x_pos);
- X my_waddstr(save_ins);
- X my_wmove(--x_pos);
- X n_iterations = 0;
- X }
- X else if (edch == 'R')
- X {
- X for (i = 0; i < indx && x_pos >= xbeg && x_pos < xend; i++)
- X my_wdelch();
- X my_waddstr(save_ins);
- X my_wmove(--x_pos);
- X n_iterations = 0;
- X }
- X else if (edit_mode == VI_c_MODE)
- X {
- X my_waddstr(save_ins);
- X n_iterations = 1;
- X edit_mode = VI_c_MODE;
- X dot_mode = NO_BEG_INS;
- X }
- X }
- X else
- X beep();
- X }
- X
- X if (edit_mode == VI_INS_MODE)
- X {
- X if (edch == ControlU)
- X {
- X wclear(win);
- X wrefresh(win);
- X die_curses();
- X }
- X else if (edch == Escape)
- X {
- X edit_mode = VI_NINS_MODE;
- X if (x_pos > xbeg)
- X my_wmove(--x_pos);
- X }
- X else if (edch == ControlW || edch == Sun_R1)
- X {
- X if (x_pos > xbeg)
- X {
- X my_wmove(--x_pos);
- X eat_white(-1, YES);
- X for (; !(isspace(winch(win))) && (x_pos >= xins_strt);)
- X {
- X my_wdelch();
- X if (x_pos == xbeg)
- X break;
- X else
- X my_wmove(--x_pos);
- X }
- X if (x_pos > xbeg && x_pos < xend - 1)
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X }
- X else if (edch == Delete)
- X {
- X if (x_pos > xbeg && x_pos > xins_strt)
- X {
- X my_wmove(--x_pos);
- X my_wdelch();
- X }
- X else
- X beep();
- X }
- X else if (isprint(edch))
- X {
- X my_winsch(edch);
- X if (indx < MAX_W_SAVED)
- X {
- X save_ins[indx] = edch;
- X save_ins[++indx] = '\0';
- X }
- X }
- X else
- X beep();
- X }
- X else if (edit_mode == VI_R_MODE)
- X {
- X if (edch == Escape)
- X {
- X if (x_pos > xbeg)
- X my_wmove(--x_pos);
- X if (x_pos > xend - 1)
- X xend = x_pos + 1;
- X edit_mode = VI_NINS_MODE;
- X }
- X else if (edch == ControlU)
- X {
- X wclear(win);
- X wrefresh(win);
- X die_curses();
- X }
- X else if (edch == Delete)
- X {
- X if (x_pos > xbeg && x_pos > xins_strt)
- X {
- X my_winsch(' ');
- X x_pos -= 2;
- X my_wmove(x_pos);
- X my_wdelch();
- X save_ins[--indx] = ' ';
- X }
- X else
- X beep();
- X }
- X else if (isprint(edch))
- X {
- X my_wdelch();
- X my_winsch(edch);
- X if (indx < MAX_W_SAVED)
- X {
- X save_ins[indx] = edch;
- X save_ins[++indx] = '\0';
- X }
- X }
- X else
- X beep();
- X }
- X else
- X {
- X stop_it = NO;
- X for (j = 0; j < n_iterations && edch != Escape; j++)
- X {
- X if (edit_mode == VI_d_MODE || edit_mode == VI_c_MODE)
- X {
- X if (edch == 'w' || edch == 'W') /* delete or change word */
- X {
- X if (x_pos < xend)
- X {
- X if (!(isalnum(winch(win))) && winch(win) != '_'
- X && edch == 'w')
- X {
- X if (x_pos < xend)
- X {
- X p_init = YES;
- X if (MAX_W_SAVED > 1)
- X {
- X save_del[0] = winch(win);
- X save_del[1] = '\0';
- X }
- X my_wdelch();
- X i = 1;
- X }
- X }
- X else
- X {
- X for (i = 0; (( edch == 'w' && (isalnum(winch(win)))
- X || edch == 'W')
- X && !(isspace(winch(win)))
- X || winch(win) == '_')
- X && (x_pos < xend);)
- X {
- X if (i < MAX_W_SAVED)
- X save_del[i] = winch(win);
- X my_wdelch();
- X ++i;
- X }
- X save_del[MIN(i, MAX_W_SAVED)] = '\0';
- X p_init = YES;
- X }
- X if (winch(win) == ' ' && x_pos <= xend - 1
- X && edit_mode != VI_c_MODE)
- X {
- X my_wdelch();
- X if (i < MAX_W_SAVED)
- X {
- X save_del[i] = ' ';
- X save_del[MIN((i + 1), MAX_W_SAVED)] = '\0';
- X }
- X }
- X }
- X else
- X beep();
- X if (x_pos == xend && edit_mode != VI_c_MODE)
- X my_wmove(--x_pos);
- X if (edit_mode == VI_d_MODE)
- X {
- X dot_cmd = edch;
- X dot_iterations = n_iterations;
- X dot_mode = VI_d_MODE;
- X }
- X if (edit_mode == VI_c_MODE)
- X {
- X if (dot_mode != NO_BEG_INS)
- X edit_mode = VI_INS_MODE;
- X else
- X {
- X edit_mode = VI_NINS_MODE;
- X my_wmove(--x_pos);
- X }
- X dot_cmd = edch;
- X dot_iterations = 1;
- X dot_mode = VI_c_MODE;
- X }
- X else if (j >= n_iterations - 1)
- X edit_mode = VI_NINS_MODE;
- X }
- X else if (edch == 'd' && edit_mode != VI_c_MODE)
- X {
- X wclear(win);
- X wrefresh(win);
- X die_curses();
- X break;
- X }
- X else
- X {
- X edit_mode = VI_NINS_MODE;
- X beep();
- X }
- X
- X }
- X else if (edit_mode == VI_r_MODE)
- X {
- X if (isprint(edch))
- X {
- X dot_mode = VI_r_MODE;
- X dot_cmd = edch;
- X my_wdelch();
- X my_winsch(edch);
- X my_wmove(--x_pos);
- X }
- X else
- X beep();
- X edit_mode = VI_NINS_MODE;
- X }
- X else
- X {
- X switch (edch)
- X {
- X case 'I':
- X dot_cmd = NO;
- X x_pos = xbeg;
- X xins_strt = x_pos;
- X my_wmove(x_pos);
- X edit_mode = VI_INS_MODE;
- X break;
- X case 'i':
- X indx = 0;
- X dot_cmd = 'i';
- X dot_iterations = 1;
- X dot_mode = VI_NINS_MODE;
- X xins_strt = x_pos;
- X edit_mode = VI_INS_MODE;
- X break;
- X case 'A':
- X dot_cmd = NO;
- X if (x_pos < xend)
- X {
- X x_pos = xend;
- X xins_strt = x_pos;
- X my_wmove(x_pos);
- X }
- X edit_mode = VI_INS_MODE;
- X break;
- X case 'a':
- X indx = 0;
- X dot_cmd = 'a';
- X dot_iterations = 1;
- X dot_mode = VI_NINS_MODE;
- X if (x_pos < xend)
- X my_wmove(++x_pos);
- X xins_strt = x_pos;
- X edit_mode = VI_INS_MODE;
- X break;
- X case ControlU:
- X case Sun_R3:
- X wclear(win);
- X wrefresh(win);
- X die_curses();
- X break;
- X case ControlW: /* Delete backwards to next space */
- X case Sun_R1:
- X dot_cmd = ControlW;
- X dot_iterations = n_iterations;
- X dot_mode = VI_NINS_MODE;
- X if (x_pos > xbeg)
- X {
- X if (x_pos != xend - 1)
- X my_wmove(--x_pos);
- X eat_white(-1, YES);
- X for (; !(isspace(winch(win))) && (x_pos >= xbeg);)
- X {
- X my_wdelch();
- X if (x_pos == xbeg)
- X break;
- X else
- X my_wmove(--x_pos);
- X }
- X if (x_pos > xbeg && x_pos < xend - 1)
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X break;
- X case 'b': /* move back to beginning of previous word */
- X case 'B':
- X case Sun_R4:
- X if (x_pos > xbeg)
- X {
- X my_wmove(--x_pos);
- X eat_white(-1, NO);
- X for (; !(isspace(winch(win))) && (x_pos > xbeg);)
- X {
- X my_wmove(--x_pos);
- X }
- X if (x_pos > xbeg)
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X break;
- X case 'w': /* move forward to beginning of next word */
- X case 'W':
- X case Sun_R6:
- X if (x_pos < xend - 1)
- X {
- X eat_white(1, NO);
- X for (; !(isspace(winch(win))) && (x_pos < xend - 1);)
- X {
- X my_wmove(++x_pos);
- X }
- X if (x_pos < xend - 1)
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X break;
- X case ControlL: /* redraw win */
- X savex_pos = x_pos;
- X win_to_cmd();
- X wclear(win);
- X wrefresh(win);
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X break;
- X case BackSpace:
- X case KEY_LEFT:
- X case KEY_BACKSPACE:
- X case 'h':
- X case Sun_R10:
- X if (x_pos > xbeg)
- X my_wmove(--x_pos);
- X else
- X beep();
- X break;
- X case EscapeM: /* move cursor to middle */
- X case Sun_R11:
- X x_pos = xbeg + (xend - xbeg) / 2;
- X my_wmove(x_pos);
- X break;
- X case KEY_RIGHT:
- X case 'l':
- X case ' ':
- X case Sun_R12:
- X if (x_pos < xend - 1)
- X my_wmove(++x_pos);
- X else
- X beep();
- X break;
- X case KEY_UP: /* move upward in history list */
- X case 'k':
- X case Sun_R8:
- X if (cur_cmd > 0)
- X {
- X --cur_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(--x_pos);
- X }
- X else
- X beep();
- X break;
- X case KEY_DOWN: /* move downward in history list */
- X case 'j':
- X case Sun_R14:
- X if (cur_cmd < last_hline)
- X {
- X ++cur_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(--x_pos);
- X }
- X else
- X beep();
- X break;
- X case 'n': /* search history list backwards */
- X if ((tmp_cmd = index_cmd(cur_cmd - 1, -1)) != cur_cmd)
- X {
- X cur_cmd = tmp_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(--x_pos);
- X }
- X else
- X beep();
- X break;
- X case '\^':
- X case Sun_R7:
- X my_wmove(xbeg);
- X x_pos = xbeg;
- X break;
- X case '\$':
- X case Sun_R13:
- X case Sun_R9:
- X x_pos = xend - 1;
- X my_wmove(x_pos);
- X break;
- X case 'D': /* delete to end of line */
- X if (x_pos < xend)
- X {
- X p_init = YES;
- X dot_cmd = NO;
- X for (i = 0; (xend - x_pos) > 0; i++)
- X {
- X if (i < MAX_W_SAVED)
- X {
- X save_del[i] = winch(win);
- X save_del[MIN((i + 1), MAX_W_SAVED)] = '\0';
- X }
- X my_wdelch();
- X }
- X if (x_pos == xend)
- X my_wmove(--x_pos);
- X }
- X else
- X beep();
- X break;
- X case 'C': /* delete to end of line and insert */
- X if (x_pos < xend)
- X {
- X dot_cmd = NO;
- X xins_strt = x_pos;
- X for (i = xend; i > x_pos; i--)
- X {
- X my_wdelch();
- X }
- X edit_mode = VI_INS_MODE;
- X }
- X else
- X beep();
- X break;
- X case 'J':
- X x_pos = xend;
- X my_wmove(x_pos);
- X my_winsch(' ');
- X add_hline();
- X break;
- X case 'p':
- X case 'P':
- X if (p_init == YES)
- X {
- X if (edch == 'p')
- X my_wmove(++x_pos);
- X my_waddstr(save_del);
- X my_wmove(--x_pos);
- X }
- X else
- X beep();
- X break;
- X case 'x': /* delete current character */
- X dot_cmd = 'x';
- X dot_iterations = n_iterations;
- X dot_mode = VI_NINS_MODE;
- X p_init = YES;
- X if (j < MAX_W_SAVED)
- X {
- X save_del[j] = winch(win);
- X save_del[MIN((j + 1), MAX_W_SAVED)] = '\0';
- X }
- X if (x_pos == xend - 1 && stop_it == NO)
- X {
- X if (j <= n_iterations - 1)
- X stop_it = YES;
- X my_wdelch();
- X my_wmove(--x_pos);
- X }
- X else if (x_pos != xend - 1)
- X {
- X if (x_pos >= xbeg)
- X {
- X my_wdelch();
- X }
- X else
- X beep();
- X }
- X break;
- X case 'X': /* delete character before cursor */
- X dot_cmd = 'X';
- X dot_iterations = n_iterations;
- X dot_mode = VI_NINS_MODE;
- X if (x_pos > xbeg)
- X {
- X my_wmove(--x_pos);
- X p_init = YES;
- X if ((n_iterations - j - 1) < MAX_W_SAVED)
- X {
- X save_del[n_iterations - j - 1] = winch(win);
- X save_del[MIN(n_iterations, MAX_W_SAVED)] = '\0';
- X }
- X my_wdelch();
- X }
- X else
- X beep();
- X break;
- X case EscapeL: /* lower case whole command */
- X case Sun_R2:
- X savex_pos = x_pos;
- X win_to_cmd();
- X case_lower();
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X break;
- X case EscapeU: /* upper case whole command */
- X savex_pos = x_pos;
- X win_to_cmd();
- X case_upper();
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X break;
- X case '\~': /* toggle case of current character */
- X case Sun_R5:
- X tch = winch(win);
- X if (isupper(tch))
- X {
- X wdelch(win);
- X winsch(win, tolower(tch));
- X }
- X else if (islower(tch))
- X {
- X wdelch(win);
- X winsch(win, toupper(tch));
- X }
- X if (x_pos < xend - 1)
- X my_wmove(++x_pos);
- X break;
- X default:
- X beep();
- X break;
- X }
- X }
- X }
- X }
- X wrefresh(win);
- X if (xend <= xbeg)
- X die_curses();
- X }
- X win_to_cmd();
- X#ifdef SYSVcurses /* reset tty */
- X if (ioctl(0, TCSETA, &tio) != 0)
- X perror("ioctl");
- X#else
- X if (ioctl(0, TIOCSETC, &tco) != 0)
- X perror("ioctl");
- X#endif
- X NOCBREAKF();
- X echo();
- X endwin();
- X return; /* finished, execute command */
- X}
- SHAR_EOF
- if test 15455 -ne "`wc -c < 'vi_edit.c'`"
- then
- echo shar: error transmitting "'vi_edit.c'" '(should have been 15455 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'emacs_edit.c'" '(7558 characters)'
- if test -f 'emacs_edit.c'
- then
- echo shar: will not over-write existing file "'emacs_edit.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'emacs_edit.c'
- X/*
- X * This software is Copyright (c) 1991 by Andy Knight
- X *
- X * Permission is hereby granted to copy, distribute or otherwise
- X * use any part of this package as long as you do not try to make
- X * money from it or pretend that you wrote it. This copyright
- X * notice must be maintained in any copy made.
- X *
- X * Use of this software constitutes acceptance for use in an AS IS
- X * condition. There are NO warranties with regard to this software.
- X * In no event shall the author be liable for any damages whatsoever
- X * arising out of or in connection with the use or performance of this
- X * software. Any use of this software is at the user's own risk.
- X *
- X * If you make modifications to this software that you feel
- X * increases it usefulness for the rest of the community, please
- X * email the changes, enhancements, bug fixes as well as any and
- X * all ideas to me. This software is going to be maintained and
- X * enhanced as deemed necessary by the community.
- X *
- X * " ... Freely you have recieved, freely give" <Matthew 10:8>
- X *
- X * Andy Knight
- X * aknight@ourgang.prime.com
- X */
- X
- X#include "config.h"
- X
- Xextern char *hist[], cstr[];
- Xextern int xbeg, cur_cmd, last_hline, pwolfe_getch();
- Xextern int edit_mode, x_pos, savex_pos, xend;
- X
- Xextern void my_wmove(), add_hline(), cmd_to_win(), win_to_cmd();
- Xextern void my_waddstr(), my_winsch(), case_upper();
- Xextern void my_wdelch(), case_lower(), eat_white();
- Xextern SIGTYPE die_curses(), die_normal();
- Xextern WINDOW *win;
- X
- X#ifdef SYSVcurses
- X extern struct termio tio, tin;
- X#else
- X extern struct tchars tco, tcn;
- X#endif
- X
- X
- Xedit_cmd()
- X{
- X int edch, tch, i, tmp_cmd;
- X fprintf(stdout,"\n");
- X if(initscr() == ERR)
- X {
- X fprintf(stderr, "Curses won't initialize - help!\n");
- X die_normal();
- X }
- X signal(SIGINT,die_curses); /* die cleanly */
- X CBREAKF();
- X noecho();
- X#ifdef SYSVcurses
- X win = newwin(2,COLS,0,0);
- X#else
- X clearok(curscr, FALSE); /* SYSV curses clears it anyway ;-( */
- X win = newwin(2,COLS,LINES-2,0);
- X#endif
- X
- X cmd_to_win();
- X wrefresh(win);
- X
- X#ifdef SYSVcurses /* disable STOP/START (CTRL-S) */
- X if(ioctl(0, TCGETA, &tio) != 0)
- X perror("ioctl");
- X tin = tio;
- X tin.c_iflag &= ~IXON;
- X if(ioctl(0, TCSETA, &tin) != 0)
- X perror("ioctl");
- X#else
- X if(ioctl(0, TIOCGETC, &tco) != 0)
- X perror("ioctl");
- X tcn = tco;
- X tcn.t_stopc = -1;
- X if(ioctl(0, TIOCSETC, &tcn) != 0)
- X perror("ioctl");
- X#endif
- X edit_mode = EMACS_MODE;
- X for (; (edch = pwolfe_getch(win)) != '\n';)
- X {
- X switch (edch)
- X {
- X case ControlU:
- X case Sun_R3:
- X wclear(win);
- X wrefresh(win);
- X die_curses();
- X break;
- X case ControlW: /*Delete word backwards*/
- X case EscapeDEL:
- X case Sun_R1:
- X if(x_pos > xbeg)
- X {
- X my_wmove(--x_pos);
- X eat_white(-1,YES);
- X for(;!(isspace(winch(win))) && (x_pos >= xbeg);)
- X {
- X my_wdelch();
- X if(x_pos == xbeg)
- X break;
- X else
- X my_wmove(--x_pos);
- X }
- X if(x_pos > xbeg)
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X break;
- X case EscapeB: /*move back to beginning of previous word*/
- X case Sun_R4:
- X if(x_pos > xbeg)
- X {
- X my_wmove(--x_pos);
- X eat_white(-1,NO);
- X for(;!(isspace(winch(win))) && (x_pos > xbeg);)
- X {
- X my_wmove(--x_pos);
- X }
- X if(x_pos > xbeg)
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X break;
- X case EscapeD: /*delete forward to beginning of next word*/
- X if(x_pos < xend)
- X {
- X eat_white(1,YES);
- X for(;!(isspace(winch(win))) && (x_pos < xend);)
- X {
- X my_wdelch();
- X }
- X }
- X else
- X add_hline();
- X break;
- X case EscapeF: /*move forward to beginning of next word*/
- X case Sun_R6:
- X if(x_pos < xend)
- X {
- X eat_white(1,NO);
- X for(;!(isspace(winch(win))) && (x_pos < xend);)
- X {
- X my_wmove(++x_pos);
- X }
- X }
- X else
- X beep();
- X break;
- X case ControlL: /* redraw win */
- X savex_pos = x_pos;
- X win_to_cmd();
- X wclear(win);
- X wrefresh(win);
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X break;
- X case BackSpace:
- X case KEY_LEFT:
- X case ControlB:
- X case KEY_BACKSPACE:
- X case Sun_R10:
- X if(x_pos > xbeg)
- X my_wmove(--x_pos);
- X else
- X beep();
- X break;
- X case EscapeM: /* move cursor to middle */
- X case Sun_R11:
- X x_pos = xbeg + (xend-xbeg)/2;
- X my_wmove(x_pos);
- X break;
- X case ControlF:
- X case KEY_RIGHT:
- X case Sun_R12:
- X if(x_pos < xend)
- X my_wmove(++x_pos);
- X else
- X beep();
- X break;
- X case KEY_UP: /* move upward in history list */
- X case ControlP:
- X case Sun_R8:
- X if(cur_cmd > 0)
- X {
- X --cur_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(x_pos);
- X }
- X else
- X beep();
- X break;
- X case KEY_DOWN: /* move downward in history list */
- X case ControlN:
- X case Sun_R14:
- X if(cur_cmd < last_hline)
- X {
- X ++cur_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(x_pos);
- X }
- X else
- X beep();
- X break;
- X case ControlR: /*search history list backwards*/
- X if((tmp_cmd = index_cmd(cur_cmd - 1,-1)) != cur_cmd)
- X {
- X cur_cmd = tmp_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(x_pos);
- X }
- X else
- X beep();
- X break;
- X case ControlS: /*search history list forwards*/
- X if((tmp_cmd = index_cmd(cur_cmd + 1,1)) != cur_cmd)
- X {
- X cur_cmd = tmp_cmd;
- X strcpy(cstr, hist[cur_cmd]);
- X wclear(win);
- X cmd_to_win();
- X my_wmove(x_pos);
- X }
- X else
- X beep();
- X break;
- X case ControlA:
- X case Sun_R7:
- X my_wmove(xbeg);
- X x_pos = xbeg;
- X break;
- X case ControlE:
- X case Sun_R13:
- X case Sun_R9:
- X my_wmove(xend);
- X x_pos = xend;
- X break;
- X case ControlK: /*delete to end of line*/
- X if(x_pos < xend)
- X {
- X for(i = xend; i > x_pos; i--)
- X {
- X my_wdelch();
- X }
- X }
- X else
- X add_hline();
- X break;
- X case Delete: /*delete character before cursor*/
- X if(x_pos > xbeg)
- X {
- X my_wmove(--x_pos);
- X my_wdelch();
- X }
- X else
- X beep();
- X break;
- X case ControlD: /*delete current character*/
- X if(x_pos < xend)
- X {
- X my_wdelch();
- X }
- X else
- X add_hline();
- X break;
- X case EscapeL: /*lower case whole command*/
- X case Sun_R2:
- X savex_pos = x_pos;
- X win_to_cmd();
- X case_lower();
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X break;
- X case EscapeU: /*upper case whole command*/
- X savex_pos = x_pos;
- X win_to_cmd();
- X case_upper();
- X cmd_to_win();
- X x_pos = savex_pos;
- X my_wmove(x_pos);
- X break;
- X case EscapeC: /* toggle case of current character */
- X case Sun_R5:
- X tch = winch(win);
- X if(isupper(tch))
- X {
- X wdelch(win);
- X winsch(win,tolower(tch));
- X }
- X else if(islower(tch))
- X {
- X wdelch(win);
- X winsch(win,toupper(tch));
- X }
- X if(x_pos < xend)
- X my_wmove(++x_pos);
- X break;
- X case ControlT: /* transpose characters */
- X if(x_pos > xbeg && x_pos != COLS)
- X {
- X if(x_pos == xend)
- X my_wmove(--x_pos);
- X my_wmove(--x_pos);
- X tch = winch(win);
- X wdelch(win);
- X my_wmove(++x_pos);
- X winsch(win,tch);
- X my_wmove(++x_pos);
- X }
- X else
- X beep();
- X break;
- X default: /* insert character */
- X if(isprint(edch))
- X {
- X my_winsch(edch);
- X }
- X else
- X beep();
- X break;
- X }
- X wrefresh(win);
- X if (xend == xbeg)
- X die_curses();
- X }
- X win_to_cmd();
- X#ifdef SYSVcurses /* reset tty */
- X if(ioctl(0, TCSETA, &tio) != 0)
- X perror("ioctl");
- X#else
- X if(ioctl(0, TIOCSETC, &tco) != 0)
- X perror("ioctl");
- X#endif
- X NOCBREAKF();
- X echo();
- X endwin();
- X return; /* finished, execute command */
- X}
- SHAR_EOF
- if test 7558 -ne "`wc -c < 'emacs_edit.c'`"
- then
- echo shar: error transmitting "'emacs_edit.c'" '(should have been 7558 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'getch.c'" '(3131 characters)'
- if test -f 'getch.c'
- then
- echo shar: will not over-write existing file "'getch.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'getch.c'
- X
- X/*
- X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
- X *
- X * Permission is hereby granted to copy, distribute or otherwise
- X * use any part of this package as long as you do not try to make
- X * money from it or pretend that you wrote it. This copyright
- X * notice must be maintained in any copy made.
- X *
- X * Use of this software constitutes acceptance for use in an AS IS
- X * condition. There are NO warranties with regard to this software.
- X * In no event shall the author be liable for any damages whatsoever
- X * arising out of or in connection with the use or performance of this
- X * software. Any use of this software is at the user's own risk.
- X *
- X * If you make modifications to this software that you feel
- X * increases it usefulness for the rest of the community, please
- X * email the changes, enhancements, bug fixes as well as any and
- X * all ideas to me. This software is going to be maintained and
- X * enhanced as deemed necessary by the community.
- X *
- X * Patrick J. Wolfe
- X * uunet!uiucuxc!kailand!pwolfe
- X * pwolfe@kailand.kai.com
- X */
- X
- X/*****************************************************************
- X * Modifications made by aknight to support emacs escape functions,
- X * Sun R function keys and vi escape, wiped out un-needed stuff
- X * for vt120, vt220
- X *****************************************************************/
- X
- X#include "config.h"
- X
- X#define NORMAL 100
- X#define ESCAPE 200
- X#define FKEY 300
- X
- Xextern int edit_mode;
- X
- X
- Xint
- Xpwolfe_getch(winptr)
- X WINDOW *winptr;
- X{
- X char c;
- X int state = NORMAL;
- X int fkeycount = 0;
- X
- X while (1)
- X {
- X c = wgetch(winptr); /* call the real getch() */
- X switch (state)
- X {
- X
- X case FKEY:
- X switch (c)
- X {
- X
- X /* numeric function keys */
- X case '0':
- X case '1':
- X case '2':
- X case '3':
- X case '4':
- X case '5':
- X case '6':
- X case '7':
- X case '8':
- X case '9':
- X fkeycount = (fkeycount * 10) + (c - '0');
- X break;
- X
- X/* lines deleted, aknight*/
- X
- X case 'A':
- X return KEY_UP;
- X case 'B':
- X return KEY_DOWN;
- X case 'C':
- X return KEY_RIGHT;
- X case 'D':
- X return KEY_LEFT;
- X
- X/* added by aknight, R1 - R15 keys on Sun*/
- X case 'z':
- X return fkeycount + 1000;
- X
- X default:
- X beep();
- X state = NORMAL;
- X }
- X break;
- X
- X case ESCAPE:
- X switch (c)
- X {
- X case 'O':
- X case '[':
- X state = FKEY;
- X fkeycount = 0;
- X break;
- X/* added by aknight, Escape - key functions */
- X case 'f':
- X return EscapeF;
- X case 'b':
- X return EscapeB;
- X case 'd':
- X return EscapeD;
- X case 'c':
- X return EscapeC;
- X case 'l':
- X return EscapeL;
- X case 'u':
- X return EscapeU;
- X case 'm':
- X return EscapeM;
- X case Delete:
- X return EscapeDEL;
- X case Escape:
- X state = ESCAPE;
- X break;
- X
- X default:
- X state = NORMAL;
- X beep();
- X }
- X break;
- X
- X default:
- X switch (c)
- X {
- X case Escape:
- X state = ESCAPE;
- X/* added by aknight */
- X if (edit_mode == VI_INS_MODE || edit_mode == VI_R_MODE)
- X return Escape;
- X break;
- X
- X case CSI:
- X state = FKEY;
- X fkeycount = 0;
- X break;
- X
- X default:
- X return (c);
- X }
- X }
- X }
- X}
- SHAR_EOF
- if test 3131 -ne "`wc -c < 'getch.c'`"
- then
- echo shar: error transmitting "'getch.c'" '(should have been 3131 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'getch.h'" '(2932 characters)'
- if test -f 'getch.h'
- then
- echo shar: will not over-write existing file "'getch.h'"
- else
- sed 's/^X//' << \SHAR_EOF > 'getch.h'
- X
- X/*
- X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
- X *
- X * Permission is hereby granted to copy, distribute or otherwise
- X * use any part of this package as long as you do not try to make
- X * money from it or pretend that you wrote it. This copyright
- X * notice must be maintained in any copy made.
- X *
- X * Use of this software constitutes acceptance for use in an AS IS
- X * condition. There are NO warranties with regard to this software.
- X * In no event shall the author be liable for any damages whatsoever
- X * arising out of or in connection with the use or performance of this
- X * software. Any use of this software is at the user's own risk.
- X *
- X * If you make modifications to this software that you feel
- X * increases it usefulness for the rest of the community, please
- X * email the changes, enhancements, bug fixes as well as any and
- X * all ideas to me. This software is going to be maintained and
- X * enhanced as deemed necessary by the community.
- X *
- X * Patrick J. Wolfe
- X * uunet!uiucuxc!kailand!pwolfe
- X * pwolfe@kailand.kai.com
- X */
- X
- X/*************************************************************
- X * Modifications made by aknight to add definitions for escape
- X * functions and Sun R function keys, also wiped out sections
- X * for SYSVcurses, VT120, VT220
- X ************************************************************/
- X#ifndef SYSVcurses
- X/* System V curses key names and codes returned by getch */
- X#define KEY_DOWN 0402
- X#define KEY_UP 0403
- X#define KEY_LEFT 0404
- X#define KEY_RIGHT 0405
- X#define KEY_BACKSPACE 0407
- X#endif /* NOT SYSVcurses */
- X
- X/* ascii control codes */
- X#define ControlA 001
- X#define ControlB 002
- X#define ControlC 003
- X#define ControlD 004
- X#define ControlE 005
- X#define ControlF 006
- X#define ControlG 007
- X#define ControlH 010
- X#define BackSpace 010
- X#define ControlI 011
- X#define Tab 011
- X#define ControlJ 012
- X#define LineFeed 012
- X#define ControlK 013
- X#define ControlL 014
- X#define ControlM 015
- X#define Return 015
- X#define ControlN 016
- X#define ControlO 017
- X#define ControlP 020
- X#define ControlQ 021
- X#define ControlR 022
- X#define ControlS 023
- X#define ControlT 024
- X#define ControlU 025
- X#define ControlV 026
- X#define ControlW 027
- X#define ControlX 030
- X#define ControlY 031
- X#define ControlZ 032
- X#define Escape 033
- X#define Control[ 033
- X#define Delete 0177
- X#define Del 0177
- X#define CSI 0233
- X
- X/* added by aknight */
- X
- X#define EscapeD 1001
- X#define EscapeF 1002
- X#define EscapeB 1003
- X#define EscapeDEL 1004
- X#define EscapeM 1005
- X#define EscapeC 1006
- X#define EscapeU 1007
- X#define EscapeL 1008
- X
- X#define Sun_R1 1208
- X#define Sun_R2 1209
- X#define Sun_R3 1210
- X#define Sun_R4 1211
- X#define Sun_R5 1212
- X#define Sun_R6 1213
- X#define Sun_R7 1214
- X#define Sun_R8 1215
- X#define Sun_R9 1216
- X#define Sun_R10 1217
- X#define Sun_R11 1218
- X#define Sun_R12 1219
- X#define Sun_R13 1220
- X#define Sun_R14 1221
- X#define Sun_R15 1222
- SHAR_EOF
- if test 2932 -ne "`wc -c < 'getch.h'`"
- then
- echo shar: error transmitting "'getch.h'" '(should have been 2932 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'config.h'" '(2003 characters)'
- if test -f 'config.h'
- then
- echo shar: will not over-write existing file "'config.h'"
- else
- sed 's/^X//' << \SHAR_EOF > 'config.h'
- X/*
- X * Configuration file for mced
- X */
- X
- X#define PROMPT "%McEd% " /* change to whatever you like, just make
- X * sure it is enclosed with double quotes */
- X
- X#define CBREAKF crmode /* change to cbreak if your system does not
- X * have curses compatibility routine "crmode" */
- X
- X#define NOCBREAKF nocrmode /* change to nocbreak if your system does not
- X * have curses compatibility routine
- X * "nocrmode" */
- X
- X
- X#define MIN_CMD_LEN 5 /* Min number of characters in command line
- X * to be considered worthy */
- X
- X#define MAX_CH 300 /* Max number of characters in command line */
- X
- X#define MAX_H_READ 250 /* Max number of history lines possible to
- X * read */
- X
- X#define MAX_W_SAVED 50 /* Max word length to save on edits */
- X
- X
- X#define BUFSIZE 4096 /* buffer size for file read, reads only once
- X * so must be large enough for whole history file.
- X * (If you need more than 4096
- X * you should join packrats anonymous!! :-) */
- X
- X/*
- X * the following is from config.h for scan by Patrick J. Wolfe:
- X */
- X
- X/*
- X * Define "SIGTYPE" to the type of the value returned by the "signal"
- X * system call. On BSD 4.2 systems, it's "void". On BSD 4.3 and SVR3
- X * systems, it's "int".
- X *
- X * Define "SYSVcurses" if your system only has System V curses.
- X */
- X
- X#define SIGTYPE int
- X
- X#define beep() fprintf (stderr, "\007");
- X
- X#define YES 1
- X#define NO 0
- X
- X#define MIN(a, b) (((a) < (b)) ? (a) : (b))
- X
- X#define EMACS_MODE 1 /* dont edit these, see the Makefile */
- X#define VI_INS_MODE 2 /* to select emacs mode or vi mode */
- X
- X#define VI_NINS_MODE 3
- X#define VI_c_MODE 4
- X#define VI_d_MODE 5
- X#define VI_r_MODE 6
- X#define VI_R_MODE 7
- X#define NO_BEG_INS 8
- X
- X
- X#include "getch.h"
- X
- X/* {string,strings}.h file definitions */
- Xextern char *strcpy(), *strncpy(), *strcat(), *strncat();
- Xextern int strcmp(), strncmp(), strlen();
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <signal.h>
- X#include <curses.h>
- X#include <errno.h>
- X
- X#ifdef SYSVcurses
- X#include <termio.h>
- X#else
- X#include <sys/ioctl.h>
- X#endif
- SHAR_EOF
- if test 2003 -ne "`wc -c < 'config.h'`"
- then
- echo shar: error transmitting "'config.h'" '(should have been 2003 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-